#pragma once
#include "Database.h"

#ifdef DBMS_USE_ODBC

#if defined( WIN32 ) || defined ( WIN64 )

#include <windows.h>
#include <Odbcinst.h>
#include <Sql.h>
#include <sqlext.h>
#include <Sqltypes.h>
#include <Sqlucode.h>
#include <Msdasql.h>
#include <Msdadc.h>


LIBDBC_BEGIN_NAMESPACE

class Odbc : public Database
{
public:
	Odbc();
	~Odbc();

protected:
	virtual bool _connect(const char* host, const char* database, const char* user, const char* pwd, int port = 0);
	virtual bool _connect(const char* host, const char* user, const char* pwd, int port = 0);
	virtual bool _close();

	virtual void _use(const char* database);
	virtual IResultSet* _execQuery(const char* query);
	virtual int _execNonQuery(const char* query);

	virtual void _storeConnectionInfo(const char* host, const char* user, const char* pwd, int port);
	virtual void _storeDatabaseName(const char* database);
	virtual bool _createConnectedHDBC(SQLHDBC* hdbc);
	virtual void _internalSwitchDatabase(HDBC hdbc, const char* database);

	bool _isSuccess(SQLRETURN rc);

protected:
	static int      _nInstances;
	static SQLHENV  _hEnv;
	SQLHDBC         _hDbc;

	char* _host;
	char* _database;
	char* _user;
	char* _pwd;
	int _port;

};

LIBDBC_END_NAMESPACE


#endif // WIN32 ) || defined ( WIN64 )
#endif
